﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pb;

public class PDKChat : MonoBehaviour {

    public List<GameObject> textChat;
    public List<GameObject> faceChat;


    private void Awake()
    {
        for (int i = 0; i < textChat.Count; i++)
        {
            UIEventListener.Get(textChat[i]).onClick = ButtonClick;
        }

        for (int i = 0; i < faceChat.Count; i++)
        {
            UIEventListener.Get(faceChat[i]).onClick = ButtonClick;
        }
    }

    void ButtonClick(GameObject button)
    {
        if (button.name.Contains("t"))
        {
            //文字聊天
            RoomChatType RCT = RoomChatType.TextId;
            Send(RCT, button.name.Substring(0, 1));
        }
        else
        {
            RoomChatType RCT = RoomChatType.MovieClip;
            Send(RCT, button.name);
        }
    }

    void Send(RoomChatType RCT, string content)
    {
        RoomChatRequest lg = new Pb.RoomChatRequest { MsgType = RCT, Content = content };
        SocketManager socketManager = SocketManager.Instance;
        socketManager.SendProtobuf1(lg, MsgId.RoomChatRequest);
        Destroy(gameObject);
    }

    public void DestroySelf()
    {
        Destroy(gameObject);
    }
}
